<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@include file="../head.jsp"%>
<!-- 页面内容 -start -->
<div id="bodyCentent" style="margin-top: 50px;">
	<!-- panel -->
	<div class="_panel">
		<!--  -->
		<div class="_panel-header">
			<div class="_left">
				<h3>SQL基本配置&nbsp;&nbsp;${CusBase.name}</h3>
			</div>
			<div class="_right">
				<label class="_right _green" onclick="showAlert({title:'自定义配置说明',msg:'.customAbout',msgType:'jquery',btnOkShow:false})">说明文档</label> <label class="_right _green" disabled>预览</label> <label
					class="_right _green" onclick="getSelect('defForm')">ckForm</label> <label class="_red mr10 bra5">*&nbsp; 所有输入项均为必填项</label>
			</div>
			<div class="clear"></div>
		</div>
		<div class="_panel-content">
			<form method="post" id="defForm">
				<div class="_grow">
					<input type="hidden" name="id" value="${CusBase.id}" /> <span class="g-2-24"><label>主题名称：</label></span> <span class="g-4-24"> <input name="name" type="text" value="${CusBase.name}"
						readonly="readonly" /></span> <span class="g-2-24"><label>是否分页：</label></span> <span class="g-1-24"> <select name="boLimit">
							<option value="1" ${CusBase.boLimit==1?'selected':''}>分</option>
							<option value="0" ${CusBase.boLimit==0?'selected':''}>不分</option>
					</select>
					</span> <span class="g-2-24"><label>一页条数：</label></span> <span class="g-1-24"> <input name="limiSize" type="number" value="${CusBase.limiSize==0?15:CusBase.limiSize}" /></span> <span class="g-2-24"><label>是否显示复选框：</label></span>
					<span class="g-1-24"> <select name="boCheckbox">
							<option value="1" ${CusBase.boCheckbox==1?'selected':''}>显示</option>
							<option value="0" ${CusBase.boCheckbox==0?'selected':''}>不显示</option>
					</select>
					</span> <span class="g-2-24"><label>是否显示导出：</label></span> <span class="g-1-24"> <select name="boExport">
							<option value="1" ${CusBase.boExport==1?'selected':''}>显示</option>
							<option value="0" ${CusBase.boExport==0?'selected':''}>不显示</option>
					</select>
					</span> <span class="g-2-24"><label>选择数据源：</label></span> <span class="g-2-24"> <select name="dataSource">
							<option value="1">测试读库</option>
							<option value="0">正式读库</option>
					</select>
					</span>
					<div class="clear"></div>
				</div>
				<div class="_grow">
					<span class="g-2-24"><label>SQL查询语句：</label></span> <span class="g-22-24"><textarea rows="10" cols="" name="sqlSelect">${CusBase.sqlSelect}</textarea> </span>
					<div class="clear"></div>
				</div>
			</form>
		</div>

		<!--  -->
		<div class="_panel-header">
			<div class="_left">
				<h3>搜索条件配置</h3>
			</div>
			<div class="_right">
				<label class="_right _green" onclick="copyNew('.rowSearch')">添加新项</label> <label class="_right _def hide" onclick="getSelect('SearchForm')">ckForm</label>
			</div>
			<div class="clear"></div>
		</div>
		<div class="_panel-content">
			<form method="post" id="SearchForm">
				<div class="clear"></div>
				<table class="_table">
					<thead>
						<tr>
							<td>搜索名称</td>
							<td>字段名</td>
							<td width="20%">类型</td>
							<td>允许为空</td>
							<td>默认值</td>
							<td width="100px;" style="text-align: center;">操作</td>
						</tr>
					</thead>
					<tbody class="rowSearch">
						<c:forEach items="${crudselect}" var="item">
							<tr>
								<td><input type="hidden" name="id" value="${item.id}" /> <input name="name" type="text" value="${item.name}" /></td>
								<td><input name="code" type="text" value="${item.code}" /></td>
								<td><select name="type"><option value="11" ${item.type==11?'selected':''}>字符</option>
										<option value="12" ${item.type==12?'selected':''}>数字</option>
										<option value="13" ${item.type==13?'selected':''}>日期：年-月-日</option>
										<option value="14" ${item.type==14?'selected':''}>日期：年-月-日 时:分</option>
										<option value="15">时间： 时:分</option></select></td>
								<td><select name="boNull"><option value="1" ${item.boNull==1?'selected':''}>允许</option>
										<option value="0" ${item.boNull==0?'selected':''}>不允许</option></select></td>
								<td><textarea rows="1" cols="" name="def">${item.def}</textarea></td>
								<td style="text-align: center;">
									<button type="button" class="_green" title="上移" onclick="trToUp(this)">↑</button>
									<button type="button" class="_green" title="下移" onclick="trToDown(this)">↓</button>
									<button type="button" class="_red" title="删除当前行" onclick="trToDel(this)">X</button>
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</form>
		</div>
		<!--  -->
		<!--  -->
		<div class="_panel-header">
			<div class="_left">
				<h3>显示列/隐藏列配置</h3>
			</div>
			<div class="_right">
				<label class="_right _green" onclick="getSelect('ColForm')">ckForm</label>
			</div>
			<div class="clear"></div>
		</div>
		<div class="_panel-content">
			<div class="rowColDemo hide">
				<div class="_grow ">
					<span class="g-2-24"><label>显示列名：</label></span> <span class="g-3-24"> <input name="name" type="text" />
					</span> <span class="g-2-24"><label>字段名：</label></span> <span class="g-3-24"> <input name="code" type="text" />
					</span> <span class="g-2-24"><label>是否显示：</label></span> <span class="g-3-24"> <select name="boShow" lazy="true"><option value="1">显示</option>
							<option value="0">不显示</option></select>
					</span>
					<div class="clear"></div>
				</div>
			</div>
			<form method="post" id="ColForm">
				<div class="clear"></div>
				<div class="rowCol">

					<c:forEach items="${crudshow}" var="item">
						<div class="_grow ">
							<input type="hidden" name="id" value="${item.id}" /> <span class="g-2-24"><label>显示列名：</label></span> <span class="g-3-24"> <input name="name" type="text" value="${item.name}" />
							</span> <span class="g-2-24"><label>字段名：</label></span> <span class="g-3-24"> <input name="code" type="text" value="${item.code}" />
							</span> <span class="g-2-24"><label>是否显示：</label></span> <span class="g-3-24"> <select name="boShow"><option value="1" ${item.boShow==1?'selected':''}>显示</option>
									<option value="0" ${item.boShow==0?'selected':''}>不显示</option></select>
							</span>
							<div class="clear"></div>
						</div>
					</c:forEach>

				</div>
			</form>
			<div clss="_grow" style="margin-bottom: 10px;">
				<button type="button" class=" _green" onclick="copyNew('.rowCol')">添加新项</button>
				<button type="button" class="_red" onclick="delOld('.rowCol')">删除</button>
			</div>
		</div>
		<!--  -->
		<!--  -->
		<div class="_panel-header">
			<div class="_left">
				<h3>新增操作列配置</h3>
			</div>
			<div class="_right">
				<label class="_right _green" onclick="getSelect('AddForm')">ckForm</label>
			</div>
			<div class="clear"></div>
		</div>
		<div class="_panel-content">
			<div class="rowAddDemo hide">
				<div class="_grow ">
					<span class="g-2-24"><label>搜索名称：</label></span> <span class="g-3-24"> <input name="name" type="text" />
					</span> <span class="g-2-24"><label>字段名：</label></span> <span class="g-3-24"> <input name="code" type="text" />
					</span> <span class="g-2-24"><label>类型：</label></span> <span class="g-3-24"> <select name="type" lazy="true"><option value="11">字符</option>
							<option value="12">数字</option>
							<option value="13">日期：年-月-日</option>
							<option value="14">日期：年-月-日 时:分</option>
							<option value="15">时间： 时:分</option></select>
					</span> <span class="g-2-24"><label>允许为空：</label></span> <span class="g-2-24"> <select name="boNull" lazy="true"><option value="1">允许</option>
							<option value="0">不允许</option></select>
					</span> <span class="g-2-24"><label>默认值：</label></span> <span class="g-3-24"> <input name="def" type="text" />
					</span>
					<div class="clear"></div>
				</div>
			</div>
			<form method="post" id="AddForm">
				<div class="_grow ${fn:length(CusBase.sqlInsert)>0?'':'hide'}">
					<span class="g-2-24"><label>新增SQL：</label></span> <span class="g-22-24"> <textarea name="sqlInsert" rows="4" cols="">${CusBase.sqlInsert}</textarea>
					</span>
					<div class="clear"></div>
				</div>
				<div class="rowAdd">
					<c:forEach items="${crudinsert}" var="item">
						<div class="_grow ">
							<input type="hidden" name="id" value="${item.id}" /> <span class="g-2-24"><label>搜索名称：</label></span> <span class="g-3-24"> <input name="name" type="text" value="${item.name}" />
							</span> <span class="g-2-24"><label>字段名：</label></span> <span class="g-3-24"> <input name="code" type="text" value="${item.code}" />
							</span> <span class="g-2-24"><label>类型：</label></span> <span class="g-3-24"> <select name="type"><option value="11" ${item.type==11?'selected':''}>字符</option>
									<option value="12" ${item.type==12?'selected':''}>数字</option>
									<option value="13" ${item.type==13?'selected':''}>日期：年-月-日</option>
									<option value="14" ${item.type==14?'selected':''}>日期：年-月-日 时:分</option>
									<option value="15">时间： 时:分</option></select>
							</span> <span class="g-2-24"><label>允许为空：</label></span> <span class="g-2-24"> <select name="boNull"><option value="1" ${item.boNull==1?'selected':''}>允许</option>
									<option value="0" ${item.boNull==0?'selected':''}>不允许</option></select>
							</span> <span class="g-2-24"><label>默认值：</label></span> <span class="g-3-24"> <input name="def" type="text" value="${item.def}" />
							</span>
							<div class="clear"></div>
						</div>
					</c:forEach>

				</div>
			</form>
			<div clss="_grow" style="margin-bottom: 10px;">
				<button type="button" class=" _green" onclick="copyNew('.rowAdd')">添加新项</button>
				<button type="button" class="_red" onclick="delOld('.rowAdd')">删除</button>
			</div>
		</div>
		<!--  -->
		<!--  -->
		<div class="_panel-header">
			<div class="_left">
				<h3>修改操作列配置</h3>
			</div>
			<div class="_right">
				<label class="_right _green" onclick="getSelect('EditForm')">ckForm</label>
			</div>
			<div class="clear"></div>
		</div>
		<div class="_panel-content">
			<div class="rowEditDemo hide">
				<div class="_grow ">
					<span class="g-2-24"><label>修改参数名：</label></span> <span class="g-3-24"> <input name="name" type="text" /></span> <span class="g-2-24"><label>字段名：</label></span> <span class="g-3-24"> <input
						name="code" type="text" />
					</span> <span class="g-2-24"><label>类型：</label></span> <span class="g-3-24"> <select name="type" lazy="true"><option value="11">字符</option>
							<option value="12">数字</option>
							<option value="13">日期：年-月-日</option>
							<option value="14">日期：年-月-日 时:分</option>
							<option value="15">时间： 时:分</option></select>
					</span> <span class="g-2-24"><label>允许为空：</label></span> <span class="g-2-24"> <select name="boNull" lazy="true"><option value="1">允许</option>
							<option value="0">不允许</option></select>
					</span> <span class="g-2-24"><label>默认值：</label></span> <span class="g-3-24"> <input name="def" type="text" />
					</span>
					<div class="clear"></div>
				</div>
			</div>
			<form method="post" id="EditForm">
				<div class="_grow ${fn:length(CusBase.sqlUpdate)>0?'':'hide'}">
					<span class="g-2-24"><label>修改SQL：</label></span> <span class="g-22-24"> <textarea name="sqlUpdate" rows="4" cols="">${CusBase.sqlUpdate}</textarea>
					</span>
					<div class="clear"></div>
				</div>
				<div class="rowEdit">

					<c:forEach items="${crudupdate}" var="item">
						<div class="_grow ">
							<input type="hidden" name="id" value="${item.id}" /> <span class="g-2-24"><label>搜索名称：</label></span> <span class="g-3-24"> <input name="name" type="text" value="${item.name}" />
							</span> <span class="g-2-24"><label>字段名：</label></span> <span class="g-3-24"> <input name="code" type="text" value="${item.code}" />
							</span> <span class="g-2-24"><label>类型：</label></span> <span class="g-3-24"> <select name="type"><option value="11" ${item.type==11?'selected':''}>字符</option>
									<option value="12" ${item.type==12?'selected':''}>数字</option>
									<option value="13" ${item.type==13?'selected':''}>日期：年-月-日</option>
									<option value="14" ${item.type==14?'selected':''}>日期：年-月-日 时:分</option>
									<option value="15">时间： 时:分</option></select>
							</span> <span class="g-2-24"><label>允许为空：</label></span> <span class="g-2-24"> <select name="boNull"><option value="1" ${item.boNull==1?'selected':''}>允许</option>
									<option value="0" ${item.boNull==0?'selected':''}>不允许</option></select>
							</span> <span class="g-2-24"><label>默认值：</label></span> <span class="g-3-24"> <input name="def" type="text" value="${item.def}" />
							</span>
							<div class="clear"></div>
						</div>
					</c:forEach>
				</div>
			</form>
			<div clss="_grow" style="margin-bottom: 10px;">
				<button type="button" class=" _green" onclick="copyNew('.rowEdit')">添加新项</button>
				<button type="button" class="_red" onclick="delOld('.rowEdit')">删除</button>
			</div>
		</div>
		<!--  -->
		<!--  -->
		<div class="_panel-header">
			<div class="_left">
				<h3>删除操作列配置</h3>
			</div>
			<div class="_right">
				<label class="_right _green" onclick="getSelect('DelForm')">ckForm</label>
			</div>
			<div class="clear"></div>
		</div>
		<div class="_panel-content">
			<div class="rowDelDemo hide">
				<div class="_grow ">
					<span class="g-2-24"><label>字段名：</label></span> <span class="g-3-24"> <input name="code" type="text" />
					</span>
					<div class="clear"></div>
				</div>
			</div>
			<form method="post" id="DelForm">
				<div class="_grow ${fn:length(CusBase.sqlDelete)>0?'':'hide'}">
					<span class="g-2-24"><label>删除SQL：</label></span> <span class="g-22-24"> <textarea name="sqlDelete" rows="4" cols="">${CusBase.sqlDelete}</textarea>
					</span>
					<div class="clear"></div>
				</div>
				<div class="rowDel">

					<c:forEach items="${cruddelete}" var="item">
						<div class="_grow ">
							<input type="hidden" name="id" value="${item.id}" /> <span class="g-2-24"><label>字段名：</label></span> <span class="g-3-24"> <input name="code" type="text" value="${item.code}" />
							</span>
							<div class="clear"></div>
						</div>
					</c:forEach>

				</div>
			</form>
			<div clss="_grow">
				<button type="button" class=" _green" onclick="copyNew('.rowDel')">添加新项</button>
				<button type="button" class="_red" onclick="delOld('.rowDel')">删除</button>
			</div>
		</div>
		<!--  -->
		<div class="_form-footer " style="text-align: center;">
			<button type="button" class="_def">返回</button>
			<button type="button" class="btnOk _green " onclick="submitAll()">确认保存</button>
		</div>
	</div>
	<!-- panel -->
</div>
<div class="hide customAbout">
	<p>1、sql占位符说明</p>

</div>
<script type="text/javascript">
	function copyNew(cla) {
		$(cla).append($(cla + "Demo").html());
		$(cla).find("tr:last").find("select").each(function() {
			createSelect($(this));
		});
	}
	function trToUp(obj) {
		var $tr = $(obj).parents("tr");
		if ($tr.index() != 0) {
			$tr.prev().before($tr);
		}
	}
	function trToDown(obj) {
		var $tr = $(obj).parents("tr");
		$tr.next().after($tr);
	}
	function trToDel(obj) {
		$(obj).parents("tr").remove();
	}

	function getSelect(ids) {
		var msg = ($("#" + ids).serialize() + "").replaceAll("&", "<br/>");
		showAlert({
			msg : msg,
			btnOkShow : false
		});
	}

	function submitAll() {
		var nullVal = 0;
		$("#bodyCentent form").each(function() {
			var formId = $(this).attr("id");
			$(this).find("input,textarea").each(function(i) {
				if ($(this).val().trim() == "" && !$(this).is(":hidden")) {
					if ($(this).attr("name") == "def")
						return true;
					var _name = $(this).attr("name");
					$(this).delTips(formId + _name + i);
					$(this).addTips(formId + _name + i, ' 该项不能为空!', 'red');
					$(this).unbind("click").bind("click", function() {
						$(this).delTips(formId + _name + i);
					});
					nullVal++;
				}
			});
		});
		if (nullVal == 0) {
			var params = [];
			$("#bodyCentent form").each(function() {
				var formId = $(this).attr("id");
				var serializeVals = $(this).serialize();
				params.push([ formId, serializeVals ]);
			});
			var base64Param = $.base64.encode(params.join(";"));
			sendRequestTB("${ctx}/custom/add.html", {
				params : base64Param
			}, function(data) {
				if (data == "OK") {
					location.reload();
				} else {
					showMsg(data, "error");
				}
			});
		}
		return false;
	}
</script>
<table class="hide">
	<tbody class="rowSearchDemo">
		<tr>
			<td><input name="name" type="text" /></td>
			<td><input name="code" type="text" /></td>
			<td><select name="type" lazy="true"><option value="11">字符</option>
					<option value="12">数字</option>
					<option value="13">日期：年-月-日</option>
					<option value="14">日期：年-月-日 时:分</option>
					<option value="15">时间： 时:分</option></select></td>
			<td><select name="boNull" lazy="true"><option value="1">允许</option>
					<option value="0">不允许</option></select></td>
			<td><textarea rows="1" cols="" name="def"></textarea></td>
			<td style="text-align: center;">
				<button type="button" class="_green" title="上移" onclick="trToUp(this)">↑</button>
				<button type="button" class="_green" title="下移" onclick="trToDown(this)">↓</button>
				<button type="button" class="_red" title="删除当前行" onclick="trToDel(this)">X</button>
			</td>
		</tr>
	</tbody>
	<tbody>

	</tbody>
</table>
<%@include file="../bottom.jsp"%>